<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="vue.js"></script>
    <title>Document</title>
</head>

<body>
    <main id="app">
        <img @mousedown='down($event)' :src="src" draggable="false" alt="">
    </main>  
    <script>
        var vue = new Vue({
            el: '#app',
            data: {
                imageIndex: 0
            },
            methods: {
                down(e) {
                    // 上一位置
                    var posX = e.pageX
                    var mv = (event) => {
                        posX = this.move(event, posX)
                    }
                    document.addEventListener('mousemove', mv)
                    document.addEventListener('mouseup', function () {
                        document.removeEventListener('mousemove', mv)
                    })
                },
                move(e, posX) {
                    if (e.pageX - posX > 35) {
                        if (this.imageIndex <= 0) {
                            this.imageIndex = 35
                        }
                        else {
                            this.imageIndex--
                        }
                    }
                    else if (e.pageX - posX < -35) {
                        if (this.imageIndex >= 35) {
                            this.imageIndex = 0
                        }
                        else {
                            this.imageIndex++
                        }
                    }
                    else {
                        return posX
                    }
                    return e.pageX
                }
            },
            computed: {
                src() {
                    return './images/' + this.imageIndex + '.png'

                }
            }
        })
    </script>
</body>

</html>